<?php
require "./config/mysql.php";

class newList extends mysqlPdo
{
    public static function newinfo()

    {
        $pdo = mysqlPdo::getPdoConnect();
        $tr = $pdo -> query("select * from article_content");
        $str = $tr -> fetchAll(PDO::FETCH_ASSOC);
        $total =$tr -> rowCount();   //获取总记录数;
        $num = 10;             //每页显示的记录数;
        $url = "new.php";          //请求的URL 
        $cpage = isset($_GET["page"])?$_GET["page"]:1;//当前页  
        $pagenum = ceil($total/$num);//总页数 
        $offset = ($cpage-1)*$num;//开始去数据的位置  
        $sql1 = "select * from article_content limit {$offset},{$num}";
        $tr1 = $pdo -> query($sql1);
        $str1 = $tr1 -> fetchAll(PDO::FETCH_ASSOC);
        $start = $offset+1;//开始记录页 
        $end = ($cpage==$pagenum) ? $total : ($cpage*$num);//结束记录页 
        $next = ($cpage==$pagenum) ? $pagenum : ($cpage+1);//下一页  
        $prev = ($cpage==1) ? 1 : ($cpage-1);//前一页 
        $arr = array(
            'total'=>$total,
            'num'=>$num,
            'url'=>$url,
            'cpage'=>$cpage,
            'pagenum'=>$pagenum,
            'offset'=>$offset,
            'str1'=>$str1,
            'start'=>$start,
            'end'=>$end,
            'next'=>$next,
            'prev'=>$prev,
            );
        return $arr;   
   }



   public static function shownew($id)

   {

        $pdo = mysqlPdo::getPdoConnect();
        $tr = $pdo -> query("select * from article_content where id = $id");
        $str = $tr -> fetchAll(PDO::FETCH_ASSOC);

        $tr1=$pdo->query("select * from article_kind");
        $str1=$tr1->fetchALL(PDO::FETCH_ASSOC);

        $arr=array(

            'str'=>$str,
            'str1'=>$str1,


            );

        return $arr;

   }



   public static function editnew($title,$author,$kid,$content,$id)
   
   {
        $pdo = mysqlPdo::getPdoConnect();
        $tr = $pdo -> exec("update article_content set title='$title',author='$author',kid=$kid,content='$content' where id=$id");
        return $tr;


   }


   public static function delenew($id)

   {

      $pdo = mysqlPdo::getPdoConnect();
      $tr = $pdo -> exec("delete from article_content where id= '$id'");
      return $tr;  
   }


   public static function addnew($title,$content,$author,$addtime,$kid)

   {
      $pdo = mysqlPdo::getPdoConnect();
      $tr = $pdo -> exec("insert into article_content (title,content,author,addtime,kid) values('$title','$content','$author',$addtime,$kid)");
      return $tr;



   }

   public static function showkid()

   {
      $pdo = mysqlPdo::getPdoConnect();
      $tr=$pdo->query("select * from article_kind");
      $str=$tr->fetchALL(PDO::FETCH_ASSOC);
      return $str;

   }




}


